import {
  mapGetters
} from 'vuex'
export default {
  computed: {
    ...mapGetters('m_cart', ['total'])
  },
  watch: {
    total: {
      handler(newVal) {
        this.setBadge()
      }
    }
  },
  // 页面展示时触发
  onShow() {
    this.setBadge()
  },
  methods: {
    // 生成购物车的小圆点
    setBadge() {
      if (this.total === 0) {
        // 去除圆点
        uni.hideTabBarRedDot({
          index: 2
        })
        return
      }
      uni.setTabBarBadge({
        index: 2,
        text: this.total + '' // 转换字符串
      })
    }
  }
}
